gtkbox: Move public members to private structure
authorJavier Jardón <jjardon@gnome.org>
Mon, 24 May 2010 23:11:54 +0000 (01:11 +0200)
committerJavier Jardón <jjardon@gnome.org>
Tue, 13 Jul 2010 17:40:45 +0000 (19:40 +0200)
gtk/gtkbox.c
gtk/gtkbox.h

index c044b2f921ae7b0e5583818f13d56a296f9b4190..2451b6b60b4fec9d0d0a13bf951b79339cae0c40 100644 (file)
@@ -99,16 +99,19 @@ enum {
 };
 
 
-typedef struct _GtkBoxPrivate GtkBoxPrivate;
-
-struct _GtkBoxPrivate
+struct _GtkBoxPriv
 {
-  GtkOrientation orientation;
-  guint          default_expand : 1;
-  guint          spacing_set    : 1;
+  GtkOrientation  orientation;
+
+  GList          *children;
+
+  gint16          spacing;
+
+  guint           default_expand : 1;
+  guint           homogeneous    : 1;
+  guint           spacing_set    : 1;
 };
 
-#define GTK_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_BOX, GtkBoxPrivate))
 
 typedef struct _GtkBoxDesiredSizes GtkBoxDesiredSizes;
 typedef struct _GtkBoxSpreading    GtkBoxSpreading;
@@ -280,23 +283,28 @@ gtk_box_class_init (GtkBoxClass *class)
                                                                -1, G_MAXINT, 0,
                                                                GTK_PARAM_READWRITE));
 
-  g_type_class_add_private (object_class, sizeof (GtkBoxPrivate));
+  g_type_class_add_private (object_class, sizeof (GtkBoxPriv));
 }
 
 static void
 gtk_box_init (GtkBox *box)
 {
-  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
+  GtkBoxPriv *private;
+
+  box->priv = G_TYPE_INSTANCE_GET_PRIVATE (box,
+                                           GTK_TYPE_BOX,
+                                           GtkBoxPriv);
+  private = box->priv;
 
   gtk_widget_set_has_window (GTK_WIDGET (box), FALSE);
   gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), FALSE);
 
-  box->children = NULL;
-  box->spacing = 0;
-  box->homogeneous = FALSE;
-
   private->orientation = GTK_ORIENTATION_HORIZONTAL;
+  private->children = NULL;
+
   private->default_expand = FALSE;
+  private->homogeneous = FALSE;
+  private->spacing = 0;
   private->spacing_set = FALSE;
 }
 
@@ -307,7 +315,7 @@ gtk_box_set_property (GObject      *object,
                       GParamSpec   *pspec)
 {
   GtkBox *box = GTK_BOX (object);
-  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
+  GtkBoxPriv *private = box->priv;
 
   switch (prop_id)
     {
@@ -334,7 +342,7 @@ gtk_box_get_property (GObject    *object,
                       GParamSpec *pspec)
 {
   GtkBox *box = GTK_BOX (object);
-  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
+  GtkBoxPriv *private = box->priv;
 
   switch (prop_id)
     {
@@ -342,10 +350,10 @@ gtk_box_get_property (GObject    *object,
       g_value_set_enum (value, private->orientation);
       break;
     case PROP_SPACING:
-      g_value_set_int (value, box->spacing);
+      g_value_set_int (value, private->spacing);
       break;
     case PROP_HOMOGENEOUS:
-      g_value_set_boolean (value, box->homogeneous);
+      g_value_set_boolean (value, private->homogeneous);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -355,14 +363,17 @@ gtk_box_get_property (GObject    *object,
 
 
 static void
-count_expand_children (GtkBox *box, gint *visible_children, gint *expand_children)
+count_expand_children (GtkBox *box,
+                       gint *visible_children,
+                       gint *expand_children)
 {
+  GtkBoxPriv  *private = box->priv;
   GList       *children;
   GtkBoxChild *child;
 
   *visible_children = *expand_children = 0;
 
-  for (children = box->children; children; children = children->next)
+  for (children = private->children; children; children = children->next)
     {
       child = children->data;
 
@@ -404,7 +415,7 @@ gtk_box_size_allocate (GtkWidget     *widget,
                        GtkAllocation *allocation)
 {
   GtkBox *box = GTK_BOX (widget);
-  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
+  GtkBoxPriv *private = box->priv;
   GtkBoxChild *child;
   GList *children;
   gint nvis_children;
@@ -430,13 +441,13 @@ gtk_box_size_allocate (GtkWidget     *widget,
       gint child_size;
 
       if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
-        size = allocation->width - border_width * 2 - (nvis_children - 1) * box->spacing;
+        size = allocation->width - border_width * 2 - (nvis_children - 1) * private->spacing;
       else
-        size = allocation->height - border_width * 2 - (nvis_children - 1) * box->spacing;
+        size = allocation->height - border_width * 2 - (nvis_children - 1) * private->spacing;
 
       /* Retrieve desired size for visible children */
       i = 0;
-      children = box->children;
+      children = private->children;
       while (children)
        {
          child = children->data;
@@ -484,15 +495,15 @@ gtk_box_size_allocate (GtkWidget     *widget,
            }
        }
 
-      if (box->homogeneous)
+      if (private->homogeneous)
        {
          /* If were homogenous we still need to run the above loop to get the minimum sizes
           * for children that are not going to fill 
           */
          if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
-           size = allocation->width - border_width * 2 - (nvis_children - 1) * box->spacing;
+           size = allocation->width - border_width * 2 - (nvis_children - 1) * private->spacing;
          else
-           size = allocation->height - border_width * 2 - (nvis_children - 1) * box->spacing;
+           size = allocation->height - border_width * 2 - (nvis_children - 1) * private->spacing;
          
           extra = size / nvis_children;
         }
@@ -573,7 +584,7 @@ gtk_box_size_allocate (GtkWidget     *widget,
             }
 
          i = 0;
-          children = box->children;
+          children = private->children;
           while (children)
            {
              child = children->data;
@@ -584,7 +595,7 @@ gtk_box_size_allocate (GtkWidget     *widget,
                   if (child->pack == packing)
                     {
                       /* Assign the child's size. */
-                     if (box->homogeneous)
+                     if (private->homogeneous)
                        {
                          if (nvis_children == 1)
                             child_size = size;
@@ -626,11 +637,11 @@ gtk_box_size_allocate (GtkWidget     *widget,
 
                           if (packing == GTK_PACK_START)
                            {
-                             x += child_size + box->spacing;
+                             x += child_size + private->spacing;
                            }
                           else
                            {
-                             x -= child_size + box->spacing;
+                             x -= child_size + private->spacing;
 
                              child_allocation.x -= child_size;
                            }
@@ -654,11 +665,11 @@ gtk_box_size_allocate (GtkWidget     *widget,
 
                          if (packing == GTK_PACK_START)
                           {
-                            y += child_size + box->spacing;
+                            y += child_size + private->spacing;
                           }
                          else
                           {
-                            y -= child_size + box->spacing;
+                            y -= child_size + private->spacing;
 
                             child_allocation.y -= child_size;
                           }
@@ -780,7 +791,7 @@ gtk_box_get_child_property (GtkContainer *container,
       break;
     case CHILD_PROP_POSITION:
       i = 0;
-      for (list = GTK_BOX (container)->children; list; list = list->next)
+      for (list = GTK_BOX (container)->priv->children; list; list = list->next)
        {
          GtkBoxChild *child_entry;
 
@@ -805,6 +816,7 @@ gtk_box_pack (GtkBox      *box,
               guint        padding,
               GtkPackType  pack_type)
 {
+  GtkBoxPriv *private = box->priv;
   GtkBoxChild *child_info;
 
   g_return_if_fail (GTK_IS_BOX (box));
@@ -819,7 +831,7 @@ gtk_box_pack (GtkBox      *box,
   child_info->pack = pack_type;
   child_info->is_secondary = FALSE;
 
-  box->children = g_list_append (box->children, child_info);
+  private->children = g_list_append (private->children, child_info);
 
   gtk_widget_freeze_child_notify (child);
 
@@ -849,7 +861,7 @@ gtk_box_size_request_init (GtkSizeRequestIface *iface)
 static GtkSizeRequestMode
 gtk_box_get_request_mode  (GtkSizeRequest  *widget)
 {
-  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (widget);
+  GtkBoxPriv *private = GTK_BOX (widget)->priv;
 
   return (private->orientation == GTK_ORIENTATION_VERTICAL) ?
     GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH : GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
@@ -862,21 +874,21 @@ gtk_box_get_size (GtkSizeRequest      *widget,
                  gint                *natural_size)
 {
   GtkBox *box;
-  GtkBoxPrivate *private;
+  GtkBoxPriv *private;
   GList *children;
   gint nvis_children;
   gint border_width;
   gint minimum, natural;
 
   box = GTK_BOX (widget);
-  private = GTK_BOX_GET_PRIVATE (box);
+  private = box->priv;
   border_width = GTK_CONTAINER (box)->border_width;
 
   minimum = natural = 0;
 
   nvis_children = 0;
 
-  for (children = box->children; children; children = children->next)
+  for (children = private->children; children; children = children->next)
     {
       GtkBoxChild *child = children->data;
 
@@ -893,7 +905,7 @@ gtk_box_get_size (GtkSizeRequest      *widget,
 
           if (private->orientation == orientation)
            {
-              if (box->homogeneous)
+              if (private->homogeneous)
                 {
                   gint largest;
 
@@ -922,13 +934,13 @@ gtk_box_get_size (GtkSizeRequest      *widget,
 
   if (nvis_children > 0 && private->orientation == orientation)
     {
-      if (box->homogeneous)
+      if (private->homogeneous)
        {
          minimum *= nvis_children;
          natural *= nvis_children;
        }
-      minimum += (nvis_children - 1) * box->spacing;
-      natural += (nvis_children - 1) * box->spacing;
+      minimum += (nvis_children - 1) * private->spacing;
+      natural += (nvis_children - 1) * private->spacing;
     }
 
   minimum += border_width * 2;
@@ -963,7 +975,7 @@ gtk_box_compute_size_for_opposing_orientation (GtkBox *box,
                                               gint   *minimum_size,
                                               gint   *natural_size)
 {
-  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
+  GtkBoxPriv    *private = box->priv;
   GtkBoxChild   *child;
   GList         *children;
   gint           nvis_children;
@@ -982,10 +994,10 @@ gtk_box_compute_size_for_opposing_orientation (GtkBox *box,
       gint                 extra, i;
       gint                 child_size, child_minimum, child_natural;
 
-      size = avail_size - border_width * 2 - (nvis_children - 1) * box->spacing;
+      size = avail_size - border_width * 2 - (nvis_children - 1) * private->spacing;
 
       /* Retrieve desired size for visible children */
-      for (i = 0, children = box->children; children; children = children->next)
+      for (i = 0, children = private->children; children; children = children->next)
        {
          child = children->data;
          
@@ -1024,12 +1036,12 @@ gtk_box_compute_size_for_opposing_orientation (GtkBox *box,
            }
        }
 
-      if (box->homogeneous)
+      if (private->homogeneous)
        {
          /* If were homogenous we still need to run the above loop to get the minimum sizes
           * for children that are not going to fill 
           */
-         size = avail_size - border_width * 2 - (nvis_children - 1) * box->spacing;
+         size = avail_size - border_width * 2 - (nvis_children - 1) * private->spacing;
           extra = size / nvis_children;
         }
       else
@@ -1089,7 +1101,7 @@ gtk_box_compute_size_for_opposing_orientation (GtkBox *box,
       /* Allocate child positions. */
       for (packing = GTK_PACK_START; packing <= GTK_PACK_END; ++packing)
         {
-          for (i = 0, children = box->children; children; children = children->next)
+          for (i = 0, children = private->children; children; children = children->next)
            {
              child = children->data;
 
@@ -1098,7 +1110,7 @@ gtk_box_compute_size_for_opposing_orientation (GtkBox *box,
                   if (child->pack == packing)
                     {
                       /* Assign the child's size. */
-                     if (box->homogeneous)
+                     if (private->homogeneous)
                        {
                          if (nvis_children == 1)
                             child_size = size;
@@ -1167,7 +1179,7 @@ gtk_box_compute_size_for_orientation (GtkBox *box,
                                      gint   *minimum_size,
                                      gint   *natural_size)
 {
-  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
+  GtkBoxPriv    *private = box->priv;
   GList         *children;
   gint           nvis_children = 0;
   gint           required_size = 0, required_natural = 0, child_size, child_natural;
@@ -1175,7 +1187,7 @@ gtk_box_compute_size_for_orientation (GtkBox *box,
 
   avail_size -= GTK_CONTAINER (box)->border_width * 2;
 
-  for (children = box->children; children != NULL; 
+  for (children = private->children; children != NULL; 
        children = children->next, nvis_children++)
     {
       GtkBoxChild *child = children->data;
@@ -1207,14 +1219,14 @@ gtk_box_compute_size_for_orientation (GtkBox *box,
 
   if (nvis_children > 0)
     {
-      if (box->homogeneous)
+      if (private->homogeneous)
        {
          required_size    = largest_child   * nvis_children;
          required_natural = largest_natural * nvis_children;
        }
 
-      required_size     += (nvis_children - 1) * box->spacing;
-      required_natural  += (nvis_children - 1) * box->spacing;
+      required_size     += (nvis_children - 1) * private->spacing;
+      required_natural  += (nvis_children - 1) * private->spacing;
     }
 
   required_size    += GTK_CONTAINER (box)->border_width * 2;
@@ -1234,7 +1246,7 @@ gtk_box_get_width_for_height (GtkSizeRequest *widget,
                              gint           *natural_width)
 {
   GtkBox        *box     = GTK_BOX (widget);
-  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (widget);
+  GtkBoxPriv    *private = box->priv;
 
   if (private->orientation == GTK_ORIENTATION_VERTICAL)
     gtk_box_compute_size_for_opposing_orientation (box, height, minimum_width, natural_width); 
@@ -1249,7 +1261,7 @@ gtk_box_get_height_for_width (GtkSizeRequest *widget,
                              gint           *natural_height)
 {
   GtkBox        *box     = GTK_BOX (widget);
-  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (widget);
+  GtkBoxPriv    *private = box->priv;
 
   if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
     gtk_box_compute_size_for_opposing_orientation (box, width, minimum_height, natural_height);
@@ -1359,11 +1371,15 @@ void
 gtk_box_set_homogeneous (GtkBox  *box,
                         gboolean homogeneous)
 {
+  GtkBoxPriv *private;
+
   g_return_if_fail (GTK_IS_BOX (box));
 
-  if ((homogeneous ? TRUE : FALSE) != box->homogeneous)
+  private = box->priv;
+
+  if ((homogeneous ? TRUE : FALSE) != private->homogeneous)
     {
-      box->homogeneous = homogeneous ? TRUE : FALSE;
+      private->homogeneous = homogeneous ? TRUE : FALSE;
       g_object_notify (G_OBJECT (box), "homogeneous");
       gtk_widget_queue_resize (GTK_WIDGET (box));
     }
@@ -1383,7 +1399,7 @@ gtk_box_get_homogeneous (GtkBox *box)
 {
   g_return_val_if_fail (GTK_IS_BOX (box), FALSE);
 
-  return box->homogeneous;
+  return box->priv->homogeneous;
 }
 
 /**
@@ -1398,11 +1414,15 @@ void
 gtk_box_set_spacing (GtkBox *box,
                     gint    spacing)
 {
+  GtkBoxPriv *private;
+
   g_return_if_fail (GTK_IS_BOX (box));
 
-  if (spacing != box->spacing)
+  private = box->priv;
+
+  if (spacing != private->spacing)
     {
-      box->spacing = spacing;
+      private->spacing = spacing;
       _gtk_box_set_spacing_set (box, TRUE);
 
       g_object_notify (G_OBJECT (box), "spacing");
@@ -1424,18 +1444,18 @@ gtk_box_get_spacing (GtkBox *box)
 {
   g_return_val_if_fail (GTK_IS_BOX (box), 0);
 
-  return box->spacing;
+  return box->priv->spacing;
 }
 
 void
 _gtk_box_set_spacing_set (GtkBox  *box,
                           gboolean spacing_set)
 {
-  GtkBoxPrivate *private;
+  GtkBoxPriv *private;
 
   g_return_if_fail (GTK_IS_BOX (box));
 
-  private = GTK_BOX_GET_PRIVATE (box);
+  private = box->priv;
 
   private->spacing_set = spacing_set ? TRUE : FALSE;
 }
@@ -1443,11 +1463,11 @@ _gtk_box_set_spacing_set (GtkBox  *box,
 gboolean
 _gtk_box_get_spacing_set (GtkBox *box)
 {
-  GtkBoxPrivate *private;
+  GtkBoxPriv *private;
 
   g_return_val_if_fail (GTK_IS_BOX (box), FALSE);
 
-  private = GTK_BOX_GET_PRIVATE (box);
+  private = box->priv;
 
   return private->spacing_set;
 }
@@ -1476,6 +1496,7 @@ gtk_box_reorder_child (GtkBox    *box,
                       GtkWidget *child,
                       gint       position)
 {
+  GtkBoxPriv *priv;
   GList *old_link;
   GList *new_link;
   GtkBoxChild *child_info = NULL;
@@ -1484,7 +1505,9 @@ gtk_box_reorder_child (GtkBox    *box,
   g_return_if_fail (GTK_IS_BOX (box));
   g_return_if_fail (GTK_IS_WIDGET (child));
 
-  old_link = box->children;
+  priv = box->priv;
+
+  old_link = priv->children;
   old_position = 0;
   while (old_link)
     {
@@ -1501,14 +1524,14 @@ gtk_box_reorder_child (GtkBox    *box,
   if (position == old_position)
     return;
 
-  box->children = g_list_delete_link (box->children, old_link);
+  priv->children = g_list_delete_link (priv->children, old_link);
 
   if (position < 0)
     new_link = NULL;
   else
-    new_link = g_list_nth (box->children, position);
+    new_link = g_list_nth (priv->children, position);
 
-  box->children = g_list_insert_before (box->children, new_link, child_info);
+  priv->children = g_list_insert_before (priv->children, new_link, child_info);
 
   gtk_widget_child_notify (child, "position");
   if (gtk_widget_get_visible (child)
@@ -1535,13 +1558,16 @@ gtk_box_query_child_packing (GtkBox      *box,
                             guint       *padding,
                             GtkPackType *pack_type)
 {
+  GtkBoxPriv *private;
   GList *list;
   GtkBoxChild *child_info = NULL;
 
   g_return_if_fail (GTK_IS_BOX (box));
   g_return_if_fail (GTK_IS_WIDGET (child));
 
-  list = box->children;
+  private = box->priv;
+
+  list = private->children;
   while (list)
     {
       child_info = list->data;
@@ -1583,13 +1609,16 @@ gtk_box_set_child_packing (GtkBox      *box,
                           guint        padding,
                           GtkPackType  pack_type)
 {
+  GtkBoxPriv *private;
   GList *list;
   GtkBoxChild *child_info = NULL;
 
   g_return_if_fail (GTK_IS_BOX (box));
   g_return_if_fail (GTK_IS_WIDGET (child));
 
-  list = box->children;
+  private = box->priv;
+
+  list = private->children;
   while (list)
     {
       child_info = list->data;
@@ -1624,11 +1653,11 @@ gtk_box_set_child_packing (GtkBox      *box,
 void
 _gtk_box_set_old_defaults (GtkBox *box)
 {
-  GtkBoxPrivate *private;
+  GtkBoxPriv *private;
 
   g_return_if_fail (GTK_IS_BOX (box));
 
-  private = GTK_BOX_GET_PRIVATE (box);
+  private = box->priv;
 
   private->default_expand = TRUE;
 }
@@ -1637,11 +1666,11 @@ static void
 gtk_box_add (GtkContainer *container,
             GtkWidget    *widget)
 {
-  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (container);
+  GtkBoxPriv *priv = GTK_BOX (container)->priv;
 
   gtk_box_pack_start (GTK_BOX (container), widget,
-                      private->default_expand,
-                      private->default_expand,
+                      priv->default_expand,
+                      priv->default_expand,
                       0);
 }
 
@@ -1650,10 +1679,11 @@ gtk_box_remove (GtkContainer *container,
                GtkWidget    *widget)
 {
   GtkBox *box = GTK_BOX (container);
+  GtkBoxPriv *priv = box->priv;
   GtkBoxChild *child;
   GList *children;
 
-  children = box->children;
+  children = priv->children;
   while (children)
     {
       child = children->data;
@@ -1665,7 +1695,7 @@ gtk_box_remove (GtkContainer *container,
          was_visible = gtk_widget_get_visible (widget);
          gtk_widget_unparent (widget);
 
-         box->children = g_list_remove_link (box->children, children);
+         priv->children = g_list_remove_link (priv->children, children);
          g_list_free (children);
          g_free (child);
 
@@ -1689,10 +1719,11 @@ gtk_box_forall (GtkContainer *container,
                gpointer      callback_data)
 {
   GtkBox *box = GTK_BOX (container);
+  GtkBoxPriv *priv = box->priv;
   GtkBoxChild *child;
   GList *children;
 
-  children = box->children;
+  children = priv->children;
   while (children)
     {
       child = children->data;
@@ -1702,7 +1733,7 @@ gtk_box_forall (GtkContainer *container,
        (* callback) (child->widget, callback_data);
     }
 
-  children = g_list_last (box->children);
+  children = g_list_last (priv->children);
   while (children)
     {
       child = children->data;
index 0d0cfb07a80c2a608421eda67c3048a4a15996c8..e90648db29ab0a3dc9987b60deb951cacbc8f839 100644 (file)
@@ -47,16 +47,15 @@ G_BEGIN_DECLS
 
 
 typedef struct _GtkBox       GtkBox;
+typedef struct _GtkBoxPriv    GtkBoxPriv;
 typedef struct _GtkBoxClass   GtkBoxClass;
 
 struct _GtkBox
 {
   GtkContainer container;
 
-  /*< public >*/
-  GList *GSEAL (children);
-  gint16 GSEAL (spacing);
-  guint GSEAL (homogeneous) : 1;
+  /*< private >*/
+  GtkBoxPriv *priv;
 };
 
 struct _GtkBoxClass